import 'package:flutter/material.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:high_help_apps/common/utils/toast.dart';
import 'package:high_help_apps/common/values/colors.dart';
import 'package:high_help_apps/common/values/define.dart';
import 'package:high_help_apps/common/widgets/common/common_button.dart';
import 'package:high_help_apps/common/widgets/common/common_listtile.dart';
import 'package:high_help_apps/common/widgets/common/common_text_button.dart';
import 'package:high_help_apps/common/widgets/common/paper_tip.dart';

import 'auth_study_logic.dart';
import 'auth_study_state.dart';

class AuthStudyPage extends StatefulWidget {
  @override
  _AuthStudyPageState createState() => _AuthStudyPageState();
}

class _AuthStudyPageState extends State<AuthStudyPage> {
  final AuthStudyLogic logic = Get.put(AuthStudyLogic());
  final AuthStudyState state = Get.find<AuthStudyLogic>().state;

  @override
  Widget build(BuildContext context) {
    return _buildAuthStudyWidget(context);
  }

  Widget _buildAuthStudyWidget(context) => Column(
        children: [
          _buildPageTipHeader(),
          _buildStepBody(context),
          _buildNextButton()
        ],
      );

  /// AppBar 认证学籍
  PreferredSizeWidget _buildStepAppBar() => AppBar(
        backgroundColor: Colors.white,
        title: Text(
          '认证学籍',
          style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.w900),
        ),
        centerTitle: true,
      );

  /// 头部提示
  Widget _buildPageTipHeader() => PageHeaderTip(
        margin: EdgeInsets.symmetric(vertical: 45.r, horizontal: 20.r),
        title: '认证学籍',
        subtitle: '请填写以下信息以认证您的身份',
        child: Image.asset('assets/images/signup/user_auth.png'),
      );

  /// 构建认证列表
  Widget _buildStepBody(context) => ListView(
        padding: EdgeInsets.zero,
        physics: NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        children: ListTile.divideTiles(context: context, tiles: [
          CommonListTile(
                  title: '请选择您的学校',
                  onPressed: () => logic.chooseSchools(context),
                suffixWidget: GetBuilder<AuthStudyLogic>(
                  builder: (logic) => logic.state.school_id == null ?
                  Icon(Icons.keyboard_arrow_right) :
                  Text(logic.state.schools_list[logic.state.school_id ?? 0].name, style: TextStyle(fontSize: 18.sp),),
                ),
              ),
          CommonListTile(
                  title: '请选择您的专业',
                  onPressed: () => logic.chooseMajors(context),
            suffixWidget: GetBuilder<AuthStudyLogic>(
              builder: (logic) => logic.state.major_id == null ?
              Icon(Icons.keyboard_arrow_right) :
              Text(logic.state.major_list[logic.state.major_id ?? 0].name, style: TextStyle(fontSize: 18.sp),),
            ),
          ),
           CommonListTile(
                  title: '请选择您的入学时间',
                  onPressed: () => logic.chooseEnterYear(context),
             suffixWidget: GetBuilder<AuthStudyLogic>(
               builder: (logic) => logic.state.enter_year == null ?
               Icon(Icons.keyboard_arrow_right) :
               Text('${logic.state.enter_time_list[logic.state.enter_year ?? 0]}年', style: TextStyle(fontSize: 18.sp),),
             ),),
        ]).toList(),
      );

  /// 构建下一步按钮
  Widget _buildNextButton() => Padding(
        padding: EdgeInsets.symmetric(horizontal: 20.r, vertical: 40.r),
        child: CommonTextButton(
          title: '下一步',
          onPressed: logic.nextPage,
        ),
      );

  @override
  void dispose() {
    Get.delete<AuthStudyLogic>();
    super.dispose();
  }
}
